package com.pan.admin.module.test.context;

import com.gitee.apanlh.spring.BeanContextUtils;
import com.gitee.apanlh.util.base.Eq;
import com.pan.admin.common.constant.test.ApiTestTypeEnum;
import com.pan.admin.common.utils.DictUtils;
import org.springframework.stereotype.Component;

/**
 *  API测试上下文
 *
 *  @author Pan
 */
@Component
public class ApiTextContent {

    /**
     *  获取发送服务端发送地址
     *
     *  @param  apiTestTypeEnum 枚举
     *  @return String
     */
    public String getServerUrl(ApiTestTypeEnum apiTestTypeEnum) {
        String serverUrl = apiTestTypeEnum.getServerUrl();

        //  测试环境
        if (Eq.str("test", BeanContextUtils.getApplicationContext().getEnvironment().getActiveProfiles()[0])) {
            return "http://localhost:31000/tsapi" + serverUrl;
        }
        //  测试环境
        if (Eq.str("prod-local", BeanContextUtils.getApplicationContext().getEnvironment().getActiveProfiles()[0])) {
            return "http://localhost:31000/tsapi" + serverUrl;
        }
        //  正式环境
        String domain = DictUtils.getDictValue("common_domain", "https");
        return domain + "tsapi" + serverUrl;
    }

}
